/*
 * @Author: cmd
 * @we_chat: cmd_develop
 * @qq群: 790373986
 * @LastEditors: cmd
 * @Description: 
 * @Date: 2019-03-23 23:23:34
 * @LastEditTime: 2019-03-23 23:28:22
 */



export default class event_manager
{
    public static  _dir:any = {}; 
       
    //public static eventid = event_id.begin_event; 

    public static add_listener(event_name:number, handler:any) 
    {   
        // 订阅事件
        if (this._dir[event_name]) {
            console.error('event register');
        }
        else {           
            this._dir[event_name] = [handler];
        }
        //console.log("add_listener:",this._dir);
    }

    public static remove_listener(event_name:number) 
    {   
        // 取消订阅        
        if (!this._dir[event_name]) {
            return;
        }        
        delete this._dir[event_name];
    }

    public static dispatch_event(event_name:number,udata?:any) 
    {   
        //事件执行        
        ////console.log("params:",event_id[event_name],udata)
        if (!this._dir[event_name]) {
            return;
        }        
        if(udata == undefined)
        {
            this._dir[event_name][0]();  
        }   
        else
        {
            this._dir[event_name][0](udata);  
        }        
    }

    public static empty_event(){
        this._dir = {};
    }
    
    
}
